﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.OracleClient;


namespace CCPSIP
{
    public class OracleKitContact
    {
        private const string kOracleServer = "ISENDER.CCP.COM.TW";
        private const string kOracleUserId = "ISENDER";
        private static byte[] kOracleKey = { 0x61, 0x4B, 0x68, 0x4A, 0x4A, 0x46, 0x41, 0x32, 0x73, 0x57, 0x66, 0x45, 0x73, 0x51, 0x7A, 0x30, 0x5A, 0x6D, 0x35, 0x69, 0x77, 0x51, 0x69, 0x39, 0x67, 0x6A, 0x69, 0x56, 0x4E, 0x44 };

        private static string GetConnStrMIS()
        {
            return String.Format(
              "Data Source={0};Persist Security Info=True;User ID={1};Password={2}",
              kOracleServer, kOracleUserId, System.Text.Encoding.UTF8.GetString(kOracleKey));
        }

        /// <summary>
        /// 取得我的朋友手機門號Array
        /// </summary>
        /// <param name="userInfo">SipUserInfo物件</param>
        /// <param name="connOracle">現有的OracleConnection</param>
        /// <returns>朋友手機門號Array</returns>
        private static string[] getFriendPhones(SipUserInfo userInfo, OracleConnection connOracle)
        {
            //【01】我的朋友
            //
            HashSet<string> friendSet = new HashSet<string>();

            string selStr1 = "SELECT FriendCountry, FriendPhone FROM user_friend"
            + " WHERE UserCountry=:UserCountry AND UserPhone=:UserPhone";

            OracleCommand selCmd1 = new OracleCommand(selStr1, connOracle);
            selCmd1.Parameters.Add("UserCountry", OracleType.VarChar).Value = userInfo.CountryCode;
            selCmd1.Parameters.Add("UserPhone", OracleType.VarChar).Value = userInfo.MobileNum;
            OracleDataAdapter adapter1 = new OracleDataAdapter(selCmd1);
            DataSet dataSet1 = new DataSet();
            adapter1.Fill(dataSet1);

            foreach (DataRow row in dataSet1.Tables[0].Rows)
            {
                string fullPhone = string.Format("{0}{1}", row["FriendCountry"], row["FriendPhone"]);
                friendSet.Add(fullPhone);
            }

            //【02】當我是朋友
            //
            HashSet<string> friendSet2 = new HashSet<string>();

            string selStr2 = "SELECT UserCountry, UserPhone FROM user_friend"
            + " WHERE FriendCountry=:FriendCountry AND FriendPhone=:FriendPhone";

            OracleCommand selCmd2 = new OracleCommand(selStr2, connOracle);
            selCmd2.Parameters.Add("FriendCountry", OracleType.VarChar).Value = userInfo.CountryCode;
            selCmd2.Parameters.Add("FriendPhone", OracleType.VarChar).Value = userInfo.MobileNum;
            OracleDataAdapter adapter2 = new OracleDataAdapter(selCmd2);
            DataSet dataSet2 = new DataSet();
            adapter2.Fill(dataSet2);

            foreach (DataRow row in dataSet2.Tables[0].Rows)
            {
                string fullPhone = string.Format("{0}{1}", row["UserCountry"], row["UserPhone"]);
                friendSet2.Add(fullPhone);
            }

            //【03】朋友Set取Union
            //
            friendSet.UnionWith(friendSet2);
            friendSet.Add(string.Format("{0}{1}", userInfo.CountryCode, userInfo.MobileNum));
            List<string> friendList = new List<string>(friendSet);
            friendList.Sort();
            return friendList.ToArray();
        }


        #region 外部會員取得個人通訊錄


        /// <summary>
        /// 外部會員：取得CCP朋友列表
        /// </summary>
        /// <param name="userInfo">SipUserInfo物件</param>
        /// <returns>個人通訊錄-CCP朋友</returns>
        public static ContactUser[] getCCPFriendsOfGuest(SipUserInfo userInfo)
        {
            OracleConnection connOracle = new OracleConnection(GetConnStrMIS());
            try
            {
                connOracle.Open();

                string[] myFriends = getFriendPhones(userInfo, connOracle);

                string selStr = "SELECT U.SIP_Num, U.CustomName, U.DeviceType, U.IconTime, U.IconSize"
                    //+ " FROM reg_user U, isender_person_all P"
                  + " FROM reg_user U, PERSON_ALL_MVIEW P"
                  + " WHERE U.Status='Y' AND U.UserType LIKE 'CCP%'"
                  + "   AND U.PPS_CODE=P.PPS_CODE AND P.IS_ACTIVE IN ('A','T')"
                  + string.Format(" AND CONCAT(U.CountryCode, U.MobileNum) IN ({0})", string.Join(",", myFriends))
                  + " ORDER BY "
                  + "   CASE WHEN P.DUTY_CODE='G1' THEN 'C4Z' ELSE P.DUTY_CODE END,"
                  + "   P.EMPLOYMENT_DATE, P.PPS_CODE, U.SIP_Num";
                OracleCommand selCmd = new OracleCommand(selStr, connOracle);
                OracleDataAdapter adapter = new OracleDataAdapter(selCmd);
                DataSet dataSet = new DataSet();
                adapter.Fill(dataSet);

                List<ContactUser> contactList = new List<ContactUser>();
                foreach (DataRow row in dataSet.Tables[0].Rows)
                {
                    contactList.Add(new ContactUser(row, true));
                }
                return contactList.ToArray();
            }
            finally
            {
                connOracle.Close();
            }
        }


        /// <summary>
        /// 外部會員：取得其他朋友列表
        /// </summary>
        /// <param name="userInfo">SipUserInfo物件</param>
        /// <returns>個人通訊錄-其他朋友</returns>
        public static ContactUser[] getOtherFriendsOfGuest(SipUserInfo userInfo)
        {
            OracleConnection connOracle = new OracleConnection(GetConnStrMIS());
            try
            {
                connOracle.Open();

                string[] myFriends = getFriendPhones(userInfo, connOracle);

                string selStr = "SELECT SIP_Num, CustomName, DeviceType, IconTime, IconSize"
                  + " FROM reg_user"
                  + " WHERE Status='Y' AND UserType NOT LIKE 'CCP%'"
                  + string.Format(" AND CONCAT(CountryCode,MobileNum) IN ({0})", string.Join(",", myFriends))
                  + " ORDER BY SIP_Num";
                OracleCommand selCmd = new OracleCommand(selStr, connOracle);
                OracleDataAdapter adapter = new OracleDataAdapter(selCmd);
                DataSet dataSet = new DataSet();
                adapter.Fill(dataSet);

                List<ContactUser> contactList = new List<ContactUser>();
                foreach (DataRow row in dataSet.Tables[0].Rows)
                {
                    contactList.Add(new ContactUser(row, false));
                }
                return contactList.ToArray();
            }
            finally
            {
                connOracle.Close();
            }
        }


        #endregion



        #region CCP取得個人通訊錄


        /// <summary>
        /// CCP取得個人通訊錄-依UserType區分
        /// </summary>
        /// <param name="ContactType">聯絡人的UserType</param>
        /// <param name="userInfo">SipUserInfo物件</param>
        /// <returns>個人通訊錄列表</returns>
        private static ContactUser[] getOutsideContacts(string ContactType, SipUserInfo userInfo)
        {
            OracleConnection connOracle = new OracleConnection(GetConnStrMIS());
            try
            {
                connOracle.Open();

                string[] myFriends = getFriendPhones(userInfo, connOracle);

                string selStr = "SELECT SIP_Num, CustomName, DeviceType, IconTime, IconSize, COUNTRYCODE, MOBILENUM"
                  + " FROM reg_user"
                  + " WHERE Status='Y' AND ABType=:ABType"
                  + string.Format(" AND CONCAT(CountryCode,MobileNum) IN ({0})", string.Join(",", myFriends))
                  + " ORDER BY SIP_Num";
                OracleCommand selCmd = new OracleCommand(selStr, connOracle);
                selCmd.Parameters.Add("ABType", OracleType.VarChar).Value = ContactType;
                OracleDataAdapter adapter = new OracleDataAdapter(selCmd);
                DataSet dataSet = new DataSet();
                adapter.Fill(dataSet);

                List<ContactUser> contactList = new List<ContactUser>();
                foreach (DataRow row in dataSet.Tables[0].Rows)
                {
                    contactList.Add(new ContactUser(row, false, true));
                }
                return contactList.ToArray();
            }
            finally
            {
                connOracle.Close();
            }
        }


        /// <summary>
        /// CCP取得個人通訊錄-客戶列表
        /// </summary>
        /// <param name="userInfo">SipUserInfo物件</param>
        /// <returns>個人通訊錄-客戶列表</returns>
        public static ContactUser[] getCustomers(SipUserInfo userInfo)
        {
            return getOutsideContacts("CUSTOMER", userInfo);
        }

        /// <summary>
        /// CCP取得個人通訊錄-供應商列表
        /// </summary>
        /// <param name="userInfo">SipUserInfo物件</param>
        /// <returns>個人通訊錄-供應商列表</returns>
        public static ContactUser[] getVendors(SipUserInfo userInfo)
        {
            return getOutsideContacts("VENDOR", userInfo);
        }

        /// <summary>
        /// CCP取得個人通訊錄-代理商列表
        /// </summary>
        /// <param name="userInfo">SipUserInfo物件</param>
        /// <returns>個人通訊錄-代理商列表</returns>
        public static ContactUser[] getAgents(SipUserInfo userInfo)
        {
            return getOutsideContacts("AGENT", userInfo);
        }

        /// <summary>
        /// CCP取得個人通訊錄-個人朋友列表
        /// </summary>
        /// <param name="userInfo">SipUserInfo物件</param>
        /// <returns>個人通訊錄-朋友列表</returns>
        public static ContactUser[] getPersons(SipUserInfo userInfo)
        {
            return getOutsideContacts("PERSON", userInfo);
        }


        #endregion



        #region 取得CCP通訊錄列表


        /// <summary>
        /// 取得CCP通訊錄-長春總公司
        /// </summary>
        /// <param name="userInfo">SipUserInfo物件</param>
        /// <returns>CCP通訊錄-長春總公司</returns>
        public static Dictionary<string, string>[] getCCPHQContacts(SipUserInfo userInfo)
        {
            OracleConnection connOracle = new OracleConnection(GetConnStrMIS());
            try
            {
                connOracle.Open();

                string selStr = "SELECT U.SIP_Num, U.CustomName, U.DeviceType, U.PPS_CODE,"
                  + "  CASE SUBSTR(P.DEPT_NO,3,2) WHEN 'AU' THEN 'FN' WHEN 'GA' THEN 'HR' WHEN 'RH' THEN 'SL'"
                  + "    ELSE SUBSTR(P.DEPT_NO,3,2) END AS DEPT_NO_MAIN,"
                  + "  U.IconTime, U.IconSize"
                    //+ " FROM reg_user U, isender_person_all P"
                  + " FROM reg_user U, PERSON_ALL_MVIEW P"
                  + " WHERE U.Status='Y' AND U.PPS_CODE=P.PPS_CODE AND P.IS_ACTIVE IN ('A','T')"
                  + "   AND COMPANY IN ('1','2') AND FIRM IN ('1','2') AND (WORK_HOUR=7.5 OR P.DUTY_CODE='G9')"   //WORK_HOUR = 7.5可能是要判斷台南營業處人員
                  + "   AND P.PPS_CODE NOT IN ('17545')"
                  + (userInfo.UserType == "CCP_ABROAD" ? " AND SUBSTR(P.DEPT_NO,3,2)<>'A1'" : "")
                  + " ORDER BY DEPT_NO_MAIN, CASE WHEN P.DUTY_CODE='G1' THEN 'C4Z' ELSE P.DUTY_CODE END ,"
                  + "   P.EMPLOYMENT_DATE, P.PPS_CODE, U.SIP_Num";
                OracleCommand selCmd = new OracleCommand(selStr, connOracle);
                OracleDataAdapter adapter = new OracleDataAdapter(selCmd);
                DataSet dataSet = new DataSet();
                adapter.Fill(dataSet);

                List<Dictionary<string, string>> contactList = new List<Dictionary<string, string>>();
                foreach (DataRow row in dataSet.Tables[0].Rows)
                {
                    string SIP_Num = Convert.ToString(row["SIP_Num"]);

                    Dictionary<string, string> contactInfo = new Dictionary<string, string>();
                    contactInfo["SIPNumber"] = SIP_Num;
                    string CustomName = Convert.ToString(row["CustomName"]);
                    string iDeviceFamily = AppleKit.getIDeviceFamily(Convert.ToString(row["DeviceType"]));
                    contactInfo["DisplayName"] = string.Format("{0} {1}", CustomName, iDeviceFamily);
                    contactInfo["CustomName"] = CustomName;
                    contactInfo["DEPT_NO_MAIN"] = Convert.ToString(row["DEPT_NO_MAIN"]);

                    if (row["IconSize"] == DBNull.Value)
                    {
                        contactInfo["IconTime"] = null;
                        contactInfo["IconSize"] = null;
                    }
                    else
                    {
                        contactInfo["IconTime"] = ChrisKit.toUTCTimeStr(row["IconTime"]);
                        contactInfo["IconSize"] = Convert.ToString(row["IconSize"]);
                    }
                    contactList.Add(contactInfo);
                }
                return contactList.ToArray();
            }
            finally
            {
                connOracle.Close();
            }
        }


        /// <summary>
        /// 取得CCP通訊錄-大連
        /// </summary>
        /// <param name="userInfo">SipUserInfo物件</param>
        /// <returns>CCP通訊錄-大連</returns>
        public static ContactUser[] getDCCContacts(SipUserInfo userInfo)
        {
            OracleConnection connOracle = new OracleConnection(GetConnStrMIS());
            try
            {
                connOracle.Open();
                string selStr = "SELECT U.SIP_Num, U.CustomName, U.DeviceType, U.IconTime, U.IconSize"
                    //+ " FROM reg_user U, isender_person_all P"
                  + " FROM reg_user U, PERSON_ALL_MVIEW P"
                  + " WHERE U.Status='Y' AND U.PPS_CODE=P.PPS_CODE AND P.IS_ACTIVE IN ('A','T')"
                  + "   AND COMPANY='3'"
                  + " ORDER BY CASE WHEN P.DUTY_CODE='G1' THEN 'C4Z' ELSE P.DUTY_CODE END, P.EMPLOYMENT_DATE, P.PPS_CODE, U.SIP_Num";
                OracleCommand selCmd = new OracleCommand(selStr, connOracle);
                OracleDataAdapter adapter = new OracleDataAdapter(selCmd);
                DataSet dataSet = new DataSet();
                adapter.Fill(dataSet);

                List<ContactUser> contactList = new List<ContactUser>();
                foreach (DataRow row in dataSet.Tables[0].Rows)
                {
                    contactList.Add(new ContactUser(row, true));
                }
                return contactList.ToArray();
            }
            finally
            {
                connOracle.Close();
            }
        }


        /// <summary>
        /// 取得CCP通訊錄-長捷士
        /// </summary>
        /// <param name="userInfo">SipUserInfo物件</param>
        /// <returns>CCP通訊錄-長捷士</returns>
        public static ContactUser[] getRCCTContacts(SipUserInfo userInfo)
        {
            OracleConnection connOracle = new OracleConnection(GetConnStrMIS());
            try
            {
                connOracle.Open();
                string selStr = "SELECT U.SIP_Num, U.CustomName, U.DeviceType, U.IconTime, U.IconSize"
                    //+ " FROM reg_user U, isender_person_all P"
                  + " FROM reg_user U, PERSON_ALL_MVIEW P"
                  + " WHERE U.Status='Y' AND U.PPS_CODE=P.PPS_CODE AND P.IS_ACTIVE IN ('A','T')"
                  + "   AND COMPANY='R'"
                  + " ORDER BY CASE WHEN P.DUTY_CODE='G1' THEN 'C4Z' ELSE P.DUTY_CODE END , P.EMPLOYMENT_DATE, P.PPS_CODE, U.SIP_Num";
                OracleCommand selCmd = new OracleCommand(selStr, connOracle);
                OracleDataAdapter adapter = new OracleDataAdapter(selCmd);
                DataSet dataSet = new DataSet();
                adapter.Fill(dataSet);

                List<ContactUser> contactList = new List<ContactUser>();
                foreach (DataRow row in dataSet.Tables[0].Rows)
                {
                    contactList.Add(new ContactUser(row, true));
                }
                return contactList.ToArray();
            }
            finally
            {
                connOracle.Close();
            }
        }


        /// <summary>
        /// 取得CCP通訊錄-長江
        /// </summary>
        /// <param name="userInfo">SipUserInfo物件</param>
        /// <returns>CCP通訊錄-長江</returns>
        public static ContactUser[] getChangChiangContacts(SipUserInfo userInfo)
        {
            OracleConnection connOracle = new OracleConnection(GetConnStrMIS());
            try
            {
                connOracle.Open();
                string selStr = "SELECT U.SIP_Num, U.CustomName, U.DeviceType, U.IconTime, U.IconSize"
                    //+ " FROM reg_user U, isender_person_all P"
                  + " FROM reg_user U, PERSON_ALL_MVIEW P"
                  + " WHERE U.Status='Y' AND U.PPS_CODE=P.PPS_CODE AND P.IS_ACTIVE IN ('A','T')"
                  + "   AND COMPANY='E'"
                  + " ORDER BY CASE WHEN P.DUTY_CODE='G1' THEN 'C4Z' ELSE P.DUTY_CODE END, P.EMPLOYMENT_DATE, P.PPS_CODE, U.SIP_Num";
                OracleCommand selCmd = new OracleCommand(selStr, connOracle);
                OracleDataAdapter adapter = new OracleDataAdapter(selCmd);
                DataSet dataSet = new DataSet();
                adapter.Fill(dataSet);

                List<ContactUser> contactList = new List<ContactUser>();
                foreach (DataRow row in dataSet.Tables[0].Rows)
                {
                    contactList.Add(new ContactUser(row, true));
                }
                return contactList.ToArray();
            }
            finally
            {
                connOracle.Close();
            }
        }


        /// <summary>
        /// 取得CCP通訊錄-長春日本
        /// </summary>
        /// <param name="userInfo">SipUserInfo物件</param>
        /// <returns>CCP通訊錄-長春日本</returns>
        public static ContactUser[] getCCPJContacts(SipUserInfo userInfo)
        {
            OracleConnection connOracle = new OracleConnection(GetConnStrMIS());
            try
            {
                connOracle.Open();
                string selStr = "SELECT U.SIP_Num, U.CustomName, U.DeviceType, U.IconTime, U.IconSize"
                    //+ " FROM reg_user U, isender_person_all P"
                  + " FROM reg_user U, PERSON_ALL_MVIEW P"
                  + " WHERE U.Status='Y' AND U.PPS_CODE=P.PPS_CODE AND P.IS_ACTIVE IN ('A','T')"
                  + "   AND (COMPANY='P' OR P.PPS_CODE IN ('17545'))"
                  + " ORDER BY CASE WHEN P.DUTY_CODE='G1' THEN 'C4Z' ELSE P.DUTY_CODE END, P.EMPLOYMENT_DATE, P.PPS_CODE, U.SIP_Num";
                OracleCommand selCmd = new OracleCommand(selStr, connOracle);
                OracleDataAdapter adapter = new OracleDataAdapter(selCmd);
                DataSet dataSet = new DataSet();
                adapter.Fill(dataSet);

                List<ContactUser> contactList = new List<ContactUser>();
                foreach (DataRow row in dataSet.Tables[0].Rows)
                {
                    contactList.Add(new ContactUser(row, true));
                }
                return contactList.ToArray();
            }
            finally
            {
                connOracle.Close();
            }
        }



        /// <summary>
        /// 取得CCP通訊錄-其他據點
        /// </summary>
        /// <param name="userInfo">SipUserInfo物件</param>
        /// <returns>CCP通訊錄-其他據點</returns>
        public static ContactUser[] getOtherContacts(SipUserInfo userInfo)
        {
            OracleConnection connOracle = new OracleConnection(GetConnStrMIS());
            try
            {
                connOracle.Open();
                string selStr = "SELECT U.SIP_Num, U.CustomName, U.DeviceType, U.IconTime, U.IconSize"
                    //+ " FROM reg_user U, isender_person_all P"
                  + " FROM reg_user U, PERSON_ALL_MVIEW P"
                  + " WHERE U.Status='Y' AND U.PPS_CODE=P.PPS_CODE AND P.IS_ACTIVE IN ('A','T')"
                  + "   AND NOT (COMPANY IN ('1','2') AND FIRM IN ('1','2') AND (WORK_HOUR=7.5 OR P.DUTY_CODE='G9'))"   //WORK_HOUR = 7.5可能是要判斷台南營業處人員
                  + "   AND NOT (COMPANY IN ('3','R','E'))"
                  + "   AND NOT (COMPANY='P' OR P.PPS_CODE IN ('17545'))"
                  + "   AND NOT (FIRM='5' AND COMPANY='1' AND P.PPS_CODE NOT IN ('50720','51244','21603','53203','51294','55776','55936','53889','55864','55021'))"
                  + "   AND NOT (FIRM='3' AND COMPANY='2' AND P.PPS_CODE NOT IN ('30450'))"
                  + "   AND NOT (FIRM='C' AND COMPANY='1')"
                  + "   AND NOT (FIRM='8' AND COMPANY IN ('1','2'))"
                  + "   AND NOT (FIRM='7' AND COMPANY IN ('1','2') AND P.PPS_CODE NOT IN ('71991','72070'))"
                  + "   AND NOT (FIRM='4' AND COMPANY IN ('1','2','5'))"
                  + "   AND NOT (COMPANY = '8' AND FIRM IN ('0', '2'))"
                  + "   AND NOT (COMPANY = '7' AND FIRM = '7')"
                  + "   AND NOT (COMPANY = 'G' AND FIRM = 'G')"
                  + "   AND NOT ((FIRM='A' AND COMPANY='A') OR P.PPS_CODE IN ('50720','21706','17346','29123','51244','21603','53203','73462','51294','55776','55936','53889','55864','55021'))"
                  + " ORDER BY CASE WHEN P.DUTY_CODE='G1' THEN 'C4Z' ELSE P.DUTY_CODE END, P.EMPLOYMENT_DATE, P.PPS_CODE, U.SIP_Num";
                OracleCommand selCmd = new OracleCommand(selStr, connOracle);
                OracleDataAdapter adapter = new OracleDataAdapter(selCmd);
                DataSet dataSet = new DataSet();
                adapter.Fill(dataSet);

                List<ContactUser> contactList = new List<ContactUser>();
                foreach (DataRow row in dataSet.Tables[0].Rows)
                {
                    contactList.Add(new ContactUser(row, true));
                }
                return contactList.ToArray();
            }
            finally
            {
                connOracle.Close();
            }
        }



        /// <summary>
        /// 取得CCP通訊錄-新竹廠
        /// </summary>
        /// <param name="userInfo">SipUserInfo物件</param>
        /// <returns>CCP通訊錄-新竹廠</returns>
        public static ContactUser[] getFirmSContacts(SipUserInfo userInfo)
        {
            OracleConnection connOracle = new OracleConnection(GetConnStrMIS());
            try
            {
                connOracle.Open();
                string selStr = "SELECT U.SIP_Num, U.CustomName, U.DeviceType, U.IconTime, U.IconSize"
                    //+ " FROM reg_user U, isender_person_all P"
                  + " FROM reg_user U, PERSON_ALL_MVIEW P"
                  + " WHERE U.Status='Y' AND U.PPS_CODE=P.PPS_CODE AND P.IS_ACTIVE IN ('A','T')"
                  + "   AND FIRM='5' AND COMPANY='1'"
                  + "   AND P.PPS_CODE NOT IN ('50720','51244','21603','53203','51294','55776','55936','53889','55864','55021')"
                  + " ORDER BY CASE WHEN P.DUTY_CODE='G1' THEN 'C4Z' ELSE P.DUTY_CODE END, P.EMPLOYMENT_DATE, P.PPS_CODE, U.SIP_Num";
                OracleCommand selCmd = new OracleCommand(selStr, connOracle);
                OracleDataAdapter adapter = new OracleDataAdapter(selCmd);
                DataSet dataSet = new DataSet();
                adapter.Fill(dataSet);

                List<ContactUser> contactList = new List<ContactUser>();
                foreach (DataRow row in dataSet.Tables[0].Rows)
                {
                    contactList.Add(new ContactUser(row, true));
                }
                return contactList.ToArray();
            }
            finally
            {
                connOracle.Close();
            }
        }


        /// <summary>
        /// 取得CCP通訊錄-苗栗廠
        /// </summary>
        /// <param name="userInfo">SipUserInfo物件</param>
        /// <returns>CCP通訊錄-苗栗廠</returns>
        public static ContactUser[] getFirmMContacts(SipUserInfo userInfo)
        {
            OracleConnection connOracle = new OracleConnection(GetConnStrMIS());
            try
            {
                connOracle.Open();
                string selStr = "SELECT U.SIP_Num, U.CustomName, U.DeviceType, U.IconTime, U.IconSize"
                    //+ " FROM reg_user U, isender_person_all P"
                  + " FROM reg_user U, PERSON_ALL_MVIEW P"
                  + " WHERE U.Status='Y' AND U.PPS_CODE=P.PPS_CODE AND P.IS_ACTIVE IN ('A','T')"
                  + "   AND FIRM='3' AND COMPANY='2' AND P.PPS_CODE NOT IN ('30450')"
                  + " ORDER BY CASE WHEN P.DUTY_CODE='G1' THEN 'C4Z' ELSE P.DUTY_CODE END, P.EMPLOYMENT_DATE, P.PPS_CODE, U.SIP_Num";
                OracleCommand selCmd = new OracleCommand(selStr, connOracle);
                OracleDataAdapter adapter = new OracleDataAdapter(selCmd);
                DataSet dataSet = new DataSet();
                adapter.Fill(dataSet);

                List<ContactUser> contactList = new List<ContactUser>();
                foreach (DataRow row in dataSet.Tables[0].Rows)
                {
                    contactList.Add(new ContactUser(row, true));
                }
                return contactList.ToArray();
            }
            finally
            {
                connOracle.Close();
            }
        }


        /// <summary>
        /// 取得CCP通訊錄-彰濱廠
        /// </summary>
        /// <param name="userInfo">SipUserInfo物件</param>
        /// <returns>CCP通訊錄-彰濱廠</returns>
        public static ContactUser[] getFirmCContacts(SipUserInfo userInfo)
        {
            OracleConnection connOracle = new OracleConnection(GetConnStrMIS());
            try
            {
                connOracle.Open();
                string selStr = "SELECT U.SIP_Num, U.CustomName, U.DeviceType, U.IconTime, U.IconSize"
                    //+ " FROM reg_user U, isender_person_all P"
                  + " FROM reg_user U, PERSON_ALL_MVIEW P"
                  + " WHERE U.Status='Y' AND U.PPS_CODE=P.PPS_CODE AND P.IS_ACTIVE IN ('A','T')"
                  + "   AND FIRM='C' AND COMPANY='1'"
                  + " ORDER BY CASE WHEN P.DUTY_CODE='G1' THEN 'C4Z' ELSE P.DUTY_CODE END, P.EMPLOYMENT_DATE, P.PPS_CODE, U.SIP_Num";
                OracleCommand selCmd = new OracleCommand(selStr, connOracle);
                OracleDataAdapter adapter = new OracleDataAdapter(selCmd);
                DataSet dataSet = new DataSet();
                adapter.Fill(dataSet);

                List<ContactUser> contactList = new List<ContactUser>();
                foreach (DataRow row in dataSet.Tables[0].Rows)
                {
                    contactList.Add(new ContactUser(row, true));
                }
                return contactList.ToArray();
            }
            finally
            {
                connOracle.Close();
            }
        }


        /// <summary>
        /// 取得CCP通訊錄-麥寮廠
        /// </summary>
        /// <param name="userInfo">SipUserInfo物件</param>
        /// <returns>CCP通訊錄-麥寮廠</returns>
        public static ContactUser[] getFirmLContacts(SipUserInfo userInfo)
        {
            OracleConnection connOracle = new OracleConnection(GetConnStrMIS());
            try
            {
                connOracle.Open();
                string selStr = "SELECT U.SIP_Num, U.CustomName, U.DeviceType, U.IconTime, U.IconSize"
                    //+ " FROM reg_user U, isender_person_all P"
                  + " FROM reg_user U, PERSON_ALL_MVIEW P"
                  + " WHERE U.Status='Y' AND U.PPS_CODE=P.PPS_CODE AND P.IS_ACTIVE IN ('A','T')"
                  + "   AND FIRM='8' AND COMPANY IN ('1','2')"
                  + " ORDER BY CASE WHEN P.DUTY_CODE='G1' THEN 'C4Z' ELSE P.DUTY_CODE END, P.EMPLOYMENT_DATE, P.PPS_CODE, U.SIP_Num";
                OracleCommand selCmd = new OracleCommand(selStr, connOracle);
                OracleDataAdapter adapter = new OracleDataAdapter(selCmd);
                DataSet dataSet = new DataSet();
                adapter.Fill(dataSet);

                List<ContactUser> contactList = new List<ContactUser>();
                foreach (DataRow row in dataSet.Tables[0].Rows)
                {
                    contactList.Add(new ContactUser(row, true));
                }
                return contactList.ToArray();
            }
            finally
            {
                connOracle.Close();
            }
        }


        /// <summary>
        /// 取得CCP通訊錄-高雄廠
        /// </summary>
        /// <param name="userInfo">SipUserInfo物件</param>
        /// <returns>CCP通訊錄-高雄廠</returns>
        public static ContactUser[] getFirmKContacts(SipUserInfo userInfo)
        {
            OracleConnection connOracle = new OracleConnection(GetConnStrMIS());
            try
            {
                connOracle.Open();
                string selStr = "SELECT U.SIP_Num, U.CustomName, U.DeviceType, U.IconTime, U.IconSize"
                    //+ " FROM reg_user U, isender_person_all P"
                  + " FROM reg_user U, PERSON_ALL_MVIEW P"
                  + " WHERE U.Status='Y' AND U.PPS_CODE=P.PPS_CODE AND P.IS_ACTIVE IN ('A','T')"
                  + "   AND FIRM='7' AND COMPANY IN ('1','2') AND P.PPS_CODE NOT IN ('71991','72070')"
                  + " ORDER BY CASE WHEN P.DUTY_CODE='G1' THEN 'C4Z' ELSE P.DUTY_CODE END, P.EMPLOYMENT_DATE, P.PPS_CODE, U.SIP_Num";
                OracleCommand selCmd = new OracleCommand(selStr, connOracle);
                OracleDataAdapter adapter = new OracleDataAdapter(selCmd);
                DataSet dataSet = new DataSet();
                adapter.Fill(dataSet);

                List<ContactUser> contactList = new List<ContactUser>();
                foreach (DataRow row in dataSet.Tables[0].Rows)
                {
                    contactList.Add(new ContactUser(row, true));
                }
                return contactList.ToArray();
            }
            finally
            {
                connOracle.Close();
            }
        }


        /// <summary>
        /// 取得CCP通訊錄-大發廠
        /// </summary>
        /// <param name="userInfo">SipUserInfo物件</param>
        /// <returns>CCP通訊錄-大發廠</returns>
        public static ContactUser[] getFirmDContacts(SipUserInfo userInfo)
        {
            OracleConnection connOracle = new OracleConnection(GetConnStrMIS());
            try
            {
                connOracle.Open();
                string selStr = "SELECT U.SIP_Num, U.CustomName, U.DeviceType, U.IconTime, U.IconSize"
                    //+ " FROM reg_user U, isender_person_all P"
                  + " FROM reg_user U, PERSON_ALL_MVIEW P"
                  + " WHERE U.Status='Y' AND U.PPS_CODE=P.PPS_CODE AND P.IS_ACTIVE IN ('A','T')"
                  + "   AND FIRM='4' AND COMPANY IN ('1','2','5')"
                  + " ORDER BY CASE WHEN P.DUTY_CODE='G1' THEN 'C4Z' ELSE P.DUTY_CODE END, P.EMPLOYMENT_DATE, P.PPS_CODE, U.SIP_Num";
                OracleCommand selCmd = new OracleCommand(selStr, connOracle);
                OracleDataAdapter adapter = new OracleDataAdapter(selCmd);
                DataSet dataSet = new DataSet();
                adapter.Fill(dataSet);

                List<ContactUser> contactList = new List<ContactUser>();
                foreach (DataRow row in dataSet.Tables[0].Rows)
                {
                    contactList.Add(new ContactUser(row, true));
                }
                return contactList.ToArray();
            }
            finally
            {
                connOracle.Close();
            }
        }


        /// <summary>
        /// 取得CCP通訊錄-漳州廠
        /// </summary>
        /// <param name="userInfo">SipUserInfo物件</param>
        /// <returns>CCP通訊錄-漳州廠</returns>
        public static ContactUser[] getFirmAContacts(SipUserInfo userInfo)
        {
            OracleConnection connOracle = new OracleConnection(GetConnStrMIS());
            try
            {
                connOracle.Open();
                string selStr = "SELECT U.SIP_Num, U.CustomName, U.DeviceType, U.IconTime, U.IconSize"
                    //+ " FROM reg_user U, isender_person_all P"
                  + " FROM reg_user U, PERSON_ALL_MVIEW P"
                  + " WHERE U.Status='Y' AND U.PPS_CODE=P.PPS_CODE AND P.IS_ACTIVE IN ('A','T')"
                  + "   AND ((FIRM='A' AND COMPANY='A')"
                  + "        OR P.PPS_CODE IN ('50720','21706','17346','29123','51244','21603','53203','73462','51294','55776','55936','53889','55864','55021'))"
                  + " ORDER BY CASE WHEN FIRM='A' THEN 2 ELSE 1 END, P.DUTY_CODE, P.EMPLOYMENT_DATE, P.PPS_CODE, U.SIP_Num";
                OracleCommand selCmd = new OracleCommand(selStr, connOracle);
                OracleDataAdapter adapter = new OracleDataAdapter(selCmd);
                DataSet dataSet = new DataSet();
                adapter.Fill(dataSet);

                List<ContactUser> contactList = new List<ContactUser>();
                foreach (DataRow row in dataSet.Tables[0].Rows)
                {
                    contactList.Add(new ContactUser(row, true));
                }
                return contactList.ToArray();
            }
            finally
            {
                connOracle.Close();
            }
        }

        /// <summary>
        /// 取得CCP通訊錄-台豐 
        /// </summary>
        /// <param name="userInfo">SipUserInfo物件</param>
        /// <returns>CCP通訊錄-台豐</returns>
        public static ContactUser[] getFirmTFContacts(SipUserInfo userInfo)
        {
            OracleConnection connOracle = new OracleConnection(GetConnStrMIS());
            try
            {
                connOracle.Open();
                string selStr = "SELECT U.SIP_Num, U.CustomName, U.DeviceType, U.IconTime, U.IconSize"
                    //+ " FROM reg_user U, isender_person_all P"
                  + " FROM reg_user U, PERSON_ALL_MVIEW P"
                  + " WHERE U.Status='Y' AND U.PPS_CODE=P.PPS_CODE AND P.IS_ACTIVE IN ('A','T')"
                  + " AND COMPANY = '8' AND FIRM IN ('0', '2')"
                  + " ORDER BY CASE WHEN P.DUTY_CODE='G1' THEN 'C4Z' ELSE P.DUTY_CODE END, P.EMPLOYMENT_DATE, P.PPS_CODE, U.SIP_Num";
                OracleCommand selCmd = new OracleCommand(selStr, connOracle);
                OracleDataAdapter adapter = new OracleDataAdapter(selCmd);
                DataSet dataSet = new DataSet();
                adapter.Fill(dataSet);

                List<ContactUser> contactList = new List<ContactUser>();
                foreach (DataRow row in dataSet.Tables[0].Rows)
                {
                    contactList.Add(new ContactUser(row, true));
                }
                return contactList.ToArray();
            }
            finally
            {
                connOracle.Close();
            }
        }

        /// <summary>
        /// 取得CCP通訊錄-奇美油倉 
        /// </summary>
        /// <param name="userInfo">SipUserInfo物件</param>
        /// <returns>CCP通訊錄-奇美油倉</returns>
        public static ContactUser[] getFirmCMContacts(SipUserInfo userInfo)
        {
            OracleConnection connOracle = new OracleConnection(GetConnStrMIS());
            try
            {
                connOracle.Open();
                string selStr = "SELECT U.SIP_Num, U.CustomName, U.DeviceType, U.IconTime, U.IconSize"
                    //+ " FROM reg_user U, isender_person_all P"
                  + " FROM reg_user U, PERSON_ALL_MVIEW P"
                  + " WHERE U.Status='Y' AND U.PPS_CODE=P.PPS_CODE AND P.IS_ACTIVE IN ('A','T')"
                  + " AND COMPANY = '7' AND FIRM = '7'"
                  + " ORDER BY CASE WHEN P.DUTY_CODE='G1' THEN 'C4Z' ELSE P.DUTY_CODE END, P.EMPLOYMENT_DATE, P.PPS_CODE, U.SIP_Num";
                OracleCommand selCmd = new OracleCommand(selStr, connOracle);
                OracleDataAdapter adapter = new OracleDataAdapter(selCmd);
                DataSet dataSet = new DataSet();
                adapter.Fill(dataSet);

                List<ContactUser> contactList = new List<ContactUser>();
                foreach (DataRow row in dataSet.Tables[0].Rows)
                {
                    contactList.Add(new ContactUser(row, true));
                }
                return contactList.ToArray();
            }
            finally
            {
                connOracle.Close();
            }
        }

        /// <summary>
        /// 取得CCP通訊錄-新加坡廠
        /// </summary>
        /// <param name="userInfo">SipUserInfo物件</param>
        /// <returns>CCP通訊錄-新加坡廠</returns>
        public static ContactUser[] getFirmSPContacts(SipUserInfo userInfo)
        {
            OracleConnection connOracle = new OracleConnection(GetConnStrMIS());
            try
            {
                connOracle.Open();
                string selStr = "SELECT U.SIP_Num, U.CustomName, U.DeviceType, U.IconTime, U.IconSize"
                    //+ " FROM reg_user U, isender_person_all P"
                  + " FROM reg_user U, PERSON_ALL_MVIEW P"
                  + " WHERE U.Status='Y' AND U.PPS_CODE=P.PPS_CODE AND P.IS_ACTIVE IN ('A','T')"
                  + " AND COMPANY = 'G' AND FIRM = 'G'"
                  + " ORDER BY CASE WHEN P.DUTY_CODE='G1' THEN 'C4Z' ELSE P.DUTY_CODE END, P.EMPLOYMENT_DATE, P.PPS_CODE, U.SIP_Num";
                OracleCommand selCmd = new OracleCommand(selStr, connOracle);
                OracleDataAdapter adapter = new OracleDataAdapter(selCmd);
                DataSet dataSet = new DataSet();
                adapter.Fill(dataSet);

                List<ContactUser> contactList = new List<ContactUser>();
                foreach (DataRow row in dataSet.Tables[0].Rows)
                {
                    contactList.Add(new ContactUser(row, true));
                }
                return contactList.ToArray();
            }
            finally
            {
                connOracle.Close();
            }
        }

        #endregion


        /// <summary>
        /// 把認識的門號加到 CCPSIP 朋友清單(只會加有效User)
        /// </summary>
        /// <param name="userInfo">SipUserInfo物件</param>
        /// <param name="phoneArray">認識的門號 Array(含國碼)</param>
        public static void AddFriends(SipUserInfo userInfo, string[] phoneArray)
        {
            OracleConnection connOracle = new OracleConnection(GetConnStrMIS());
            try
            {
                connOracle.Open();

                //【01】篩選有效User
                //
                string selStr1 = "SELECT CountryCode, MobileNum FROM reg_user"
                  + " WHERE Status='Y'"
                  + string.Format(" AND CONCAT(CountryCode,MobileNum) IN ({0})", string.Join(",", phoneArray))
                  + " ORDER BY CreateTime, pid";
                OracleCommand selCmd1 = new OracleCommand(selStr1, connOracle);
                OracleDataAdapter adapter1 = new OracleDataAdapter(selCmd1);
                DataSet dataSet1 = new DataSet();
                adapter1.Fill(dataSet1);

                foreach (DataRow row in dataSet1.Tables[0].Rows)
                {
                    string FriendCountry = Convert.ToString(row["CountryCode"]);
                    string FriendPhone = Convert.ToString(row["MobileNum"]);
                    if (FriendCountry == userInfo.CountryCode && FriendPhone == userInfo.MobileNum)
                        continue;//略過自己的門號


                    //【02】檢查該門號是否已在朋友清單中
                    //
                    string countStr2 = "SELECT COUNT(*) FROM user_friend"
                      + " WHERE UserCountry=:UserCountry AND UserPhone=:UserPhone"
                      + " AND FriendCountry=:FriendCountry AND FriendPhone=:FriendPhone";
                    OracleCommand countCmd2 = new OracleCommand(countStr2, connOracle);
                    countCmd2.Parameters.Add("UserCountry", OracleType.VarChar).Value = userInfo.CountryCode;
                    countCmd2.Parameters.Add("UserPhone", OracleType.VarChar).Value = userInfo.MobileNum;
                    countCmd2.Parameters.Add("FriendCountry", OracleType.VarChar).Value = FriendCountry;
                    countCmd2.Parameters.Add("FriendPhone", OracleType.VarChar).Value = FriendPhone;
                    UInt32 count = Convert.ToUInt32(countCmd2.ExecuteScalar());

                    if (count == 0)
                    {
                        //【03】若為新朋友則寫入清單
                        //
                        string insStr3 = "INSERT INTO user_friend"
                          + " (UserCountry, UserPhone, FriendCountry, FriendPhone, CreateTime, Source) VALUES"
                          + " (:UserCountry, :UserPhone, :FriendCountry, :FriendPhone, :DateTime, 'Contacts')";
                        OracleCommand insCmd3 = new OracleCommand(insStr3, connOracle);
                        insCmd3.Parameters.Add("UserCountry", OracleType.VarChar).Value = userInfo.CountryCode;
                        insCmd3.Parameters.Add("UserPhone", OracleType.VarChar).Value = userInfo.MobileNum;
                        insCmd3.Parameters.Add("FriendCountry", OracleType.VarChar).Value = FriendCountry;
                        insCmd3.Parameters.Add("FriendPhone", OracleType.VarChar).Value = FriendPhone;
                        insCmd3.Parameters.Add("DateTime", OracleType.DateTime).Value = DateTime.Now;
                        insCmd3.ExecuteNonQuery();
                    }
                }
            }
            finally
            {
                connOracle.Close();
            }
        }


        /// <summary>
        /// 二個User的手機門號互相加入朋友
        /// </summary>
        /// <param name="userInfo">SipUserInfo物件</param>
        /// <param name="friendInfo">對方的SipUserInfo物件</param>
        /// <param name="sourceType">朋友來源代碼</param>
        /// <param name="connOracle">現有的OracleConnection</param>
        public static void MakeFriends(SipUserInfo userInfo, SipUserInfo friendInfo, string sourceType, OracleConnection connOracle)
        {
            //【01】檢查參數
            //
            if (userInfo == null || friendInfo == null)
                return;

            string userPhone = userInfo.CountryCode + userInfo.MobileNum;
            string friendPhone = friendInfo.CountryCode + friendInfo.MobileNum;
            if (userPhone == friendPhone)
                return;//略過自己的門號


            //【02】檢查該門號是否已在朋友清單中
            //
            string countStr2 = "SELECT COUNT(*) FROM user_friend"
              + " WHERE UserCountry=:UserCountry AND UserPhone=:UserPhone"
              + "   AND FriendCountry=:FriendCountry AND FriendPhone=:FriendPhone";
            OracleCommand countCmd2 = new OracleCommand(countStr2, connOracle);
            countCmd2.Parameters.Add("UserCountry", OracleType.VarChar).Value = userInfo.CountryCode;
            countCmd2.Parameters.Add("UserPhone", OracleType.VarChar).Value = userInfo.MobileNum;
            countCmd2.Parameters.Add("FriendCountry", OracleType.VarChar).Value = friendInfo.CountryCode;
            countCmd2.Parameters.Add("FriendPhone", OracleType.VarChar).Value = friendInfo.MobileNum;
            UInt32 count = Convert.ToUInt32(countCmd2.ExecuteScalar());


            //【03】若為新朋友則寫入清單
            //
            string insStr3 = "INSERT INTO user_friend"
              + " (UserCountry, UserPhone, FriendCountry, FriendPhone, CreateTime, Source) VALUES"
              + " (:UserCountry, :UserPhone, :FriendCountry, :FriendPhone, :DateTime, :Source)";
            OracleCommand insCmd3 = new OracleCommand(insStr3, connOracle);
            insCmd3.Parameters.Add("UserCountry", OracleType.VarChar);
            insCmd3.Parameters.Add("UserPhone", OracleType.VarChar);
            insCmd3.Parameters.Add("FriendCountry", OracleType.VarChar);
            insCmd3.Parameters.Add("FriendPhone", OracleType.VarChar);
            insCmd3.Parameters.Add("DateTime", OracleType.DateTime).Value = DateTime.Now;
            insCmd3.Parameters.Add("Source", OracleType.VarChar).Value = sourceType;

            if (count == 0)
            {
                insCmd3.Parameters["UserCountry"].Value = userInfo.CountryCode;
                insCmd3.Parameters["UserPhone"].Value = userInfo.MobileNum;
                insCmd3.Parameters["FriendCountry"].Value = friendInfo.CountryCode;
                insCmd3.Parameters["FriendPhone"].Value = friendInfo.MobileNum;
                insCmd3.ExecuteNonQuery();
            }

            //【04】檢查該門號是否已在朋友清單中(反向)
            //
            countCmd2.Parameters["UserCountry"].Value = friendInfo.CountryCode;
            countCmd2.Parameters["UserPhone"].Value = friendInfo.MobileNum;
            countCmd2.Parameters["FriendCountry"].Value = userInfo.CountryCode;
            countCmd2.Parameters["FriendPhone"].Value = userInfo.MobileNum;
            count = Convert.ToUInt32(countCmd2.ExecuteScalar());

            if (count == 0)
            {
                //【05】若為新朋友則寫入清單(反向)
                //
                insCmd3.Parameters["UserCountry"].Value = friendInfo.CountryCode;
                insCmd3.Parameters["UserPhone"].Value = friendInfo.MobileNum;
                insCmd3.Parameters["FriendCountry"].Value = userInfo.CountryCode;
                insCmd3.Parameters["FriendPhone"].Value = userInfo.MobileNum;
                insCmd3.ExecuteNonQuery();
            }
        }
    }

    /// <summary>
    /// 聯絡人資訊
    /// </summary>
    public class ContactUser
    {
        private string _SIPNumber;
        private string _DisplayName;
        private string _CustomName;
        private string _DesktopExt;
        private string _IconTime;
        private string _IconSize;
        private string _CountryCode;
        private string _MobileNum;

        public string SIPNumber { get { return this._SIPNumber; } }
        public string DisplayName { get { return this._DisplayName; } }
        public string CustomName { get { return this._CustomName; } }
        public string DesktopExt { get { return this._DesktopExt; } }
        public string IconTime { get { return this._IconTime; } }
        public string IconSize { get { return this._IconSize; } }
        public string IconLastUpdate { get { return this._IconTime; } } //2014-06-30:待新版上線後移除
        public string CountryCode { get { return this._CountryCode; } }
        public string MobileNum { get { return this._MobileNum; } }


        public ContactUser(DataRow row, bool showDevice)
        {
            _SIPNumber = Convert.ToString(row["SIP_Num"]);
            _CustomName = Convert.ToString(row["CustomName"]);
            _DesktopExt = SipKit.getHQDesktopExt(_SIPNumber);

            if (showDevice)
            {
                string DeviceType = Convert.ToString(row["DeviceType"]);
                string iDeviceFamily = AppleKit.getIDeviceFamily(DeviceType);
                _DisplayName = string.Format("{0} {1}", _CustomName, iDeviceFamily);
            }
            else
            {
                _DisplayName = _CustomName;
            }

            if (row["IconSize"] != DBNull.Value)
            {
                _IconTime = ChrisKit.toUTCTimeStr(row["IconTime"]);
                _IconSize = Convert.ToString(row["IconSize"]);
            }
        }

        public ContactUser(DataRow row, bool showDevice, bool showMobile)
        {
            _SIPNumber = Convert.ToString(row["SIP_Num"]);
            _CustomName = Convert.ToString(row["CustomName"]);
            _DesktopExt = SipKit.getHQDesktopExt(_SIPNumber);
            _CountryCode = Convert.ToString(row["COUNTRYCODE"]);
            _MobileNum = Convert.ToString(row["MOBILENUM"]);

            if (showDevice)
            {
                string DeviceType = Convert.ToString(row["DeviceType"]);
                string iDeviceFamily = AppleKit.getIDeviceFamily(DeviceType);
                _DisplayName = string.Format("{0} {1}", _CustomName, iDeviceFamily);
            }
            else
            {
                _DisplayName = _CustomName;
            }

            if (row["IconSize"] != DBNull.Value)
            {
                _IconTime = ChrisKit.toUTCTimeStr(row["IconTime"]);
                _IconSize = Convert.ToString(row["IconSize"]);
            }
        }

        public ContactUser(string sipNumber, string customName)
        {
            _SIPNumber = sipNumber;
            _CustomName = customName;
            _DisplayName = _CustomName;
            _DesktopExt = SipKit.getHQDesktopExt(_SIPNumber);
        }

        public ContactUser(Dictionary<string, string> cInfo)
        {
            _SIPNumber = cInfo["SIPNumber"];
            _CustomName = cInfo["CustomName"];
            _DisplayName = cInfo["DisplayName"];
            _DesktopExt = SipKit.getHQDesktopExt(_SIPNumber);
            _IconTime = cInfo["IconTime"];
            _IconSize = cInfo["IconSize"];
        }
    }
}